/**
* Mouse Scroll v2 AS3 Version 2011
* This is the second version of this script. If you'd like to buy the first one,
* please go to http://activeden.net/user/xnamex/portofolio
* Thank you for buying my item!
* 
* @author xnamex
*/



package com.xnamex {	
	import flash.display.MovieClip;
	import flash.display.*;
	import flash.events.Event;
	import flash.events.EventDispatcher;

	
	public class  MouseScroll extends MovieClip {
		// A stage variable for listeneing
		public var _stage:Stage;
		
		public function MouseScroll() {
			//This is event listener is for handling stage referencing.
			// DO NOT REMOVE
			addEventListener(Event.ADDED_TO_STAGE, stageHandler);
		}
		
		// This functino is handling the adding to stage event for referencing to stageHeight or any stage property
		// DO NOT REMOVE
		private function stageHandler(e:Event):void {
			_stage = this.stage;
			removeEventListener(Event.ADDED_TO_STAGE, stageHandler);
		}
		
		
		
		// This is the function for Horizontal scrolling
		public function scrollH(movieClip:MovieClip, speed:Number):void {
			movieClip.addEventListener(Event.ENTER_FRAME, scrollFunc);
			
			function scrollFunc(e:Event):void {
				var clip:MovieClip = e.currentTarget as MovieClip;
				clip.x += (((stage.stageWidth - clip.width) / stage.stageWidth) * mouseX - clip.x) / speed;
			}
		}
		
		// This is the function for Vertical scrolling
		public function scrollV(movieClip:MovieClip, speed:Number):void {
			movieClip.addEventListener(Event.ENTER_FRAME, scrollFunc);
			
			function scrollFunc(e:Event):void {
				var clip:MovieClip = e.currentTarget as MovieClip;
				movieClip.y += (((stage.stageHeight - movieClip.height) / stage.stageHeight) * mouseY - movieClip.y) / speed;
			}
		}
		
	}
	
}